package com.zj.weather.bgviews.light;

import android.content.Context;
import android.graphics.Canvas;

/**
 * Created by zhaojie on 2018/8/14.
 */

public abstract class LightInfo {
    protected float width;
    protected float height;
    protected float cloudHeight;
    protected float curAlpha;
    protected float maxAlpha;
    protected float speed;
    protected int branch;
    protected boolean isLight = true;
    protected boolean isShining = true;
    protected int shiningCount = 0;
    protected int maxShiningCount = 0;
    //需要的情况下自定义执行，本身无任何实际意义
    protected float fraction;

    public LightInfo(float width, float height,float cloudHeight, float maxAlpha, float speed, int branch, int maxShiningCount) {
        this.width = width;
        this.height = height;
        this.cloudHeight = cloudHeight;
        this.maxAlpha = maxAlpha;
        this.speed = speed;
        this.branch = branch;
        this.maxShiningCount = maxShiningCount;
    }

    public abstract void initData(Context context);

    public boolean draw(Context context, Canvas canvas, float changeAlpha) {
        boolean isFinishLight = false;
        if (isLight) {
            curAlpha += speed;
            if (curAlpha >= maxAlpha) {
                curAlpha = maxAlpha;
                isLight = false;
            }
        } else {
            curAlpha -= speed;
            if (curAlpha < 0) {
                curAlpha = 0;
                isLight = true;
                isFinishLight = true;
            }
        }
        return isFinishLight;
    }
}
